package com.lngsyz.ywtb.biz.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lngsyz.ywtb.entity.hx.GetHxList;
import com.lngsyz.ywtb.entity.source1.SPermit;
import com.lngsyz.ywtb.mapper.source1.SPermitMapper;

import net.logstash.logback.encoder.org.apache.commons.lang.StringUtils;

@Service
public class SPermitService {
    
	@Autowired
	SPermitMapper sPermitMapper;
	
	public SPermit findById(String id) {
		if(StringUtils.isNotBlank(id)) {
			return sPermitMapper.findById(id);
		} else {
			return null;
		}
	}
	
	public void insert(SPermit sPermit) {
		if(sPermit != null) {
			sPermitMapper.insert(sPermit);
		}
	}
    
    public List<SPermit> findList(GetHxList getHxList, int page, int size){
    	Map<String, Object> param = new HashMap<String, Object>();
    	if(StringUtils.isNotBlank(getHxList.getAccept())) {
    		param.put("accept", getHxList.getAccept());
    	}
    	if(StringUtils.isNotBlank(getHxList.getCompanyId())) {
    		param.put("companyId", getHxList.getCompanyId());
    	}
    	if(StringUtils.isNotBlank(getHxList.getCustomName())) {
    		param.put("customName", getHxList.getCustomName());
    	}
    	if(StringUtils.isNotBlank(getHxList.getCustomInstCode())) {
    		param.put("customInstCode", getHxList.getCustomInstCode());
    	}
    	param.put("minSize", page <= 0 ? 0 : (page-1) * size);
		param.put("maxSize", page <= 0 ? size : page * size);
    	List<SPermit> lists = sPermitMapper.findByCondition(param);
    	return lists;
    }
    
    public int findTotal(GetHxList getHxList){
    	Map<String, Object> param = new HashMap<String, Object>();
    	if(StringUtils.isNotBlank(getHxList.getAccept())) {
    		param.put("accept", getHxList.getAccept());
    	}
    	if(StringUtils.isNotBlank(getHxList.getCompanyId())) {
    		param.put("companyId", getHxList.getCompanyId());
    	}
    	if(StringUtils.isNotBlank(getHxList.getCustomName())) {
    		param.put("customName", getHxList.getCustomName());
    	}
    	if(StringUtils.isNotBlank(getHxList.getCustomInstCode())) {
    		param.put("customInstCode", getHxList.getCustomInstCode());
    	}
    	int total = sPermitMapper.findTotal(param);
    	return total;
    }
}
